package com.study.design.pattern.pattern.structural.flyweight;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: gongsl
 * @Date: 2025-03-16 11:51
 * @description: 棋盘
 */
public class ChessBoard {
    private Map<Integer, ChessPiece> chessPieces = new HashMap<>();

    public ChessBoard(){
        init();
    }

    private void init() {
        chessPieces.put(1, new ChessPiece(ChessPieceUnitFactory.getChessPiece(1), 0, 0));
        chessPieces.put(2, new ChessPiece(ChessPieceUnitFactory.getChessPiece(2), 1, 0));
        // 省略其他棋子代码
    }

    public void move(int chessPieceId, int positionX, int positionY) {
        ChessPiece chessPiece = chessPieces.get(chessPieceId);
        System.out.println("棋子初始化状态：" + chessPiece);
        chessPiece.setPositionX(positionX);
        chessPiece.setPositionY(positionY);
        System.out.println("棋子移动后状态：" + chessPiece);
    }
}
